package com.renzhebiao.lkang.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.renzhebiao.lkang.comment.Need;
import com.renzhebiao.lkang.entity.ServiceProjectPO;
import com.renzhebiao.lkang.facade.ServiceProjectFacade;
import com.renzhebiao.lkang.master.ExecuteResult;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.ServiceProjectQuery;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 服务（首页二层图文） 前端控制器
 * </p>
 *
 * @author renzhebiao123
 * @since 2018-10-23
 */
@RestController
@RequestMapping("/service")
@Api(tags = "首页二层图文：服务项目")
public class ServiceProjectController {

    @Autowired
    private ServiceProjectFacade serviceProjectFacade;

    @ApiOperation(value = "新增联系记录", notes = "新增联系记录", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/add")
    @Need(token = true)
    public ExecuteResult<?> add(@RequestBody ServiceProjectPO po) {
        this.serviceProjectFacade.add(po);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "修改联系记录", notes = "修改联系记录", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/edit")
    @Need(token = true)
    public ExecuteResult<?> edit(@RequestBody ServiceProjectPO po) {
        this.serviceProjectFacade.edit(po);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "删除联系记录", notes = "删除联系记录", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/delete")
    @Need(token = true)
    public ExecuteResult<?> delete(@RequestBody Long id) {
        this.serviceProjectFacade.delete(id);
        return ExecuteResult.ok();
    }

    @ApiOperation(value = "查询联系记录列表", notes = "查询联系记录列表", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/list")
    public ExecuteResult<?> getServiceProjectList(@RequestBody ServiceProjectQuery param) {
        return ExecuteResult.ok(this.serviceProjectFacade.getServiceProjectList(param));
    }

    @ApiOperation(value = "查询联系记录单条", notes = "查询联系记录单条", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/get")
    public ExecuteResult<?> getServiceProject(@RequestBody Long id) {
        return ExecuteResult.ok(this.serviceProjectFacade.getServiceProject(id));
    }

    @ApiOperation(value = "分页查询联系记录", notes = "分页查询联系记录", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping("/page")
    public ExecuteResult<?> getServiceProjectByPage(@RequestBody PaginationDTO<ServiceProjectQuery, Void> paging) {
        return ExecuteResult.ok(this.serviceProjectFacade.getServiceProjectByPage(paging));
    }

}
